import React from 'react'
import './02parent.css'
class Parent extends React.Component{
state ={
    parentMsg: ''
}
    getChildMsg=(msg)=>{
        console.log('接收到子组件', msg);
       this.setState({
        parentMsg: msg
       })
    }
    render(){
        const {parentMsg} = this.state
        return (
            <div className='parent'>
                父组件：<Child getMsg={this.getChildMsg}></Child>
                <span>接收到子组件的值:{parentMsg}</span>
            </div>
        )
    }
}

class Child extends React.Component{
    state= {
        msg:' 通过this.props(类组件加this)拿到子组件getMsg属性，进行传参'
    }
    handleClick=()=>{
       
        this.props.getMsg(this.state.msg)
    }
    render(){
        return (
            <div className='Child'>
                子组件<button style={{marginLeft: '10px'}} onClick={this.handleClick}>点我，个父组件传播数据</button>
            </div>
        )
    }
}
export {Parent,Child}